/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ${USER}
 * Date: ${YEAR}-${MONTH}-${DAY}
 * Time: ${TIME}
 */
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public boolean isSubtree(TreeNode root, TreeNode subRoot) {
        if (root == null) {
            return false;
        }
        if (root.val == subRoot.val) {
            if (isSameTree(root,subRoot)) {
                return true;
            }
        }
        if (isSubtree(root.left,subRoot)) {
            return true;
        }else {
            return isSubtree(root.right,subRoot);
        }

    }
    public boolean isSameTree(TreeNode root,TreeNode subRoot) {
        if (root == null&&subRoot == null) {
            return true;
        }
        if (root != null&&subRoot == null||root == null&&subRoot != null) {
            return false;
        }
        if (root.val != subRoot.val) {
            return false;
        }
        if (isSameTree(root.left,subRoot.left)&&isSameTree(root.right,subRoot.right)) {
            return true;
        }
        return false;
    }
}